//
//  RWMainViewController.m
//  VmiSJ
//
//  Created by 汪的一声就哭了！ on 2016/12/29.
//  Copyright © 2016年 汪的一声就哭了！. All rights reserved.
//
//轮播高度
#define ScrollHeight WIDTH*197.0/720.0
#define NavHeight 64
#define TabbarHeight 49
//容器标题高度
#define TitleHeight self.fontSize*3
#import "RWMainViewController.h"

@interface RWMainViewController ()<ChooseVCViewDelegate, JXZViewControllerDelegate, DSHViewControllerDelegate, YJJViewControllerDelegate, YJSViewControllerDelegate, SDCycleScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;
@end

@implementation RWMainViewController
{
    NSMutableArray *_lunboArr;
    SDCycleScrollView *_cycle;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [_cycle adjustWhenControllerViewWillAppera];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"V米兼职";
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self obtainLunboData];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(sendAction)];
//    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:self.fontSize]} forState:UIControlStateNormal];
    _cycle = [[SDCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, ScrollHeight)];
    _cycle.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    [self.view addSubview:_cycle];
    _cycle.delegate = self;
    ChooseVCView *chooseViewC = [[ChooseVCView alloc] initWithFrame:CGRectMake(0, ScrollHeight+0, WIDTH, HEIGHT-ScrollHeight-NavHeight) btnArray:@[@"待审核",@"已拒绝",@"进行中",@"已结束"] font:[UIFont systemFontOfSize:self.fontSize] textColor:Color selectedImg:[UIImage imageNamed:@""] aSelectedColor:[UIColor whiteColor] titleRect:CGRectMake(10, 8, WIDTH-20, TitleHeight-16) titleHeight:TitleHeight];
    chooseViewC.backgroundColor = [UIColor whiteColor];
    chooseViewC.delegate = self;
    [self.view addSubview:chooseViewC];
    chooseViewC.headView.layer.borderWidth = 1;
    chooseViewC.headView.layer.borderColor = Color.CGColor;
    chooseViewC.headView.layer.cornerRadius = (TitleHeight-16)/2;
    chooseViewC.imageView.layer.cornerRadius = (TitleHeight-16)/2;
    chooseViewC.imageView.backgroundColor = Color;
    chooseViewC.imageView.clipsToBounds = YES;
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    BannerList *model = _lunboArr[index];
    WebViewController *viewC = [[WebViewController alloc] init];
    viewC.titleStr = model.title;
    viewC.url = model.url;
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
- (void)sendAction
{
    FBFirstViewController *viewC = [[FBFirstViewController alloc] init];
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
#pragma mark ----------- 容器代理方法
- (void)chooseVCViewDidChoose:(NSInteger)index and:(UIViewController *)SelViewC
{
    if ([SelViewC isKindOfClass:[DSHViewController class]]) {
        DSHViewController *viewC = (DSHViewController *)SelViewC;
        viewC.state = @"1";
    }
    if ([SelViewC isKindOfClass:[YJJViewController class]]) {
        YJJViewController *viewC = (YJJViewController *)SelViewC;
        viewC.state = @"1";
    }
    if ([SelViewC isKindOfClass:[JXZViewController class]]) {
        JXZViewController *viewC = (JXZViewController *)SelViewC;
        viewC.state = @"1";
    }
    if ([SelViewC isKindOfClass:[YJSViewController class]]) {
        YJSViewController *viewC = (YJSViewController *)SelViewC;
        viewC.state = @"1";
    }
}
- (UIViewController *)chooseVCViewForSelectedAt:(NSInteger)atIndex
{
    if (atIndex == 0) {
        DSHViewController *viewC = [[DSHViewController alloc] init];
        viewC.delegate = self;
        return viewC;
    }
    else if (atIndex == 1) {
        YJJViewController *viewC = [[YJJViewController alloc] init];
        viewC.delegate = self;
        return viewC;
    }
    else if (atIndex == 2) {
        JXZViewController *viewC = [[JXZViewController alloc] init];
        viewC.delegate = self;
        return viewC;
    }
    else {
        YJSViewController *viewC = [[YJSViewController alloc] init];
        viewC.delegate = self;
        return viewC;
    }
}
#pragma mark --------------- 待审核代理方法
//预览
- (void)DSHViewControllerChooseYuLanWith:(NSString *)urlStr
{
    WebViewController *viewC = [[WebViewController alloc] init];
    viewC.titleStr = @"预览详情";
    viewC.url = urlStr;
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
#pragma mark --------------- 已结束代理方法
//预览
- (void)YJSViewControllerChooseYuLanWith:(NSString *)urlStr
{
    WebViewController *viewC = [[WebViewController alloc] init];
    viewC.titleStr = @"预览详情";
    viewC.url = urlStr;
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
//审核
- (void)YJSViewControllerChooseSHWith:(Tasklist *)task
{
    SHRWViewController *viewC = [[SHRWViewController alloc] init];
    viewC.task_id = task.t_id;
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
#pragma mark --------------- 进行中代理方法
//审核
- (void)jxzViewControllerChooseShenheWithStr:(Tasklist *)task
{
    SHRWViewController *viewC = [[SHRWViewController alloc] init];
    viewC.task_id = task.t_id;
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}

//预览
- (void)JXZViewControllerChooseYuLanWith:(NSString *)urlStr
{
    WebViewController *viewC = [[WebViewController alloc] init];
    viewC.titleStr = @"预览详情";
    viewC.url = urlStr;
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
#pragma mark ----------- 已拒绝代理方法
- (void)YJJViewControllerChooseYuLanWith:(NSString *)urlStr
{
    WebViewController *viewC = [[WebViewController alloc] init];
    viewC.titleStr = @"预览详情";
    viewC.url = urlStr;
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -------------- 轮播图网络请求
- (void)obtainLunboData
{
    [NetRequiest handleDataWithString:[NSString stringWithFormat:@"%@",HTTPLOAD] dictionary:@{@"v1":@"shufflefigure"} HUD:YES block:^(id responseObject) {
        if ([responseObject[@"code"] isEqual:@200]) {
            NSMutableArray *array = [NSMutableArray array];
            _lunboArr = [NSMutableArray array];
            for (NSDictionary *dic in responseObject[@"result"]) {
                [array addObject:dic[@"img_url"]];
                BannerList *model = [[BannerList alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                [_lunboArr addObject:model];
            }
            _cycle.imageURLStringsGroup = array;
        } else {
            [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
        }
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
